package com.orientsec.autotest.project.system.newCaseSeq.controller;

import java.util.List;
import java.util.Map;

import com.orientsec.autotest.framework.web.domain.ZtreeStr;
import com.orientsec.autotest.project.system.newCaseSeq.domain.CaseQuery;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.orientsec.autotest.framework.aspectj.lang.annotation.Log;
import com.orientsec.autotest.framework.aspectj.lang.enums.BusinessType;
import com.orientsec.autotest.project.system.newCaseSeq.domain.NewCaseSeq;
import com.orientsec.autotest.project.system.newCaseSeq.service.INewCaseSeqService;
import com.orientsec.autotest.framework.web.controller.BaseController;
import com.orientsec.autotest.framework.web.page.TableDataInfo;
import com.orientsec.autotest.framework.web.domain.AjaxResult;
import com.orientsec.autotest.common.utils.poi.ExcelUtil;

/**
 * 案例字段信息操作处理
 *
 * @author autotest
 * @date 2020-02-17
 */
@Controller
@RequestMapping("/system/newCaseSeq")
public class NewCaseSeqController extends BaseController {
    private String prefix = "system/newCaseSeq";

    @Autowired
    private INewCaseSeqService newCaseSeqService;

    @RequiresPermissions("system:newCaseSeq:view")
    @GetMapping()
    public String newCaseSeq() {
        return prefix + "/newCaseSeq";
    }

    /**
     * 查询案例字段列表
     */
    @RequiresPermissions("system:newCaseSeq:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(NewCaseSeq newCaseSeq) {
        startPage();
        List<NewCaseSeq> list = newCaseSeqService.selectNewCaseSeqList(newCaseSeq);
        return getDataTable(list);
    }

    /**
     * 查询请求映射详情列表id
     */
    @RequiresPermissions("system:newCaseSeq:list")
    @RequestMapping("/list/{caseNo}")
    public String list(@PathVariable("caseNo") String caseNo, ModelMap mmap) {
        mmap.put("caseNo", caseNo);
        return prefix + "/newCaseSeq";
    }


    /**
     * 导出案例字段列表
     */
    @RequiresPermissions("system:newCaseSeq:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(NewCaseSeq newCaseSeq) {
        List<NewCaseSeq> list = newCaseSeqService.selectNewCaseSeqList(newCaseSeq);
        ExcelUtil<NewCaseSeq> util = new ExcelUtil<NewCaseSeq>(NewCaseSeq.class);
        return util.exportExcel(list, "newCaseSeq");
    }

    /**
     * 新增案例字段
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存案例字段
     */
    @RequiresPermissions("system:newCaseSeq:add")
    @Log(title = "案例字段", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(NewCaseSeq newCaseSeq) {
        return toAjax(newCaseSeqService.insertNewCaseSeq(newCaseSeq));
    }

    /**
     * 修改案例字段
     */
    @GetMapping("/edit/{caseNo}")
    public String edit(@PathVariable("caseNo") String caseNo, ModelMap mmap) {
        NewCaseSeq newCaseSeq = newCaseSeqService.selectNewCaseSeqById(caseNo);
        mmap.put("newCaseSeq", newCaseSeq);
        return prefix + "/edit";
    }

    /**
     * 修改保存案例字段
     */
    @RequiresPermissions("system:newCaseSeq:edit")
    @Log(title = "案例字段", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(NewCaseSeq newCaseSeq) {
        return toAjax(newCaseSeqService.updateNewCaseSeq(newCaseSeq));
    }

    /**
     * 删除案例字段
     */
    @RequiresPermissions("system:newCaseSeq:remove")
    @Log(title = "案例字段", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(newCaseSeqService.deleteNewCaseSeqByIds(ids));
    }


    /**
     * 加载部门列表树
     */
    @GetMapping("/treeData/{caseNo}")
    @ResponseBody
    public List<ZtreeStr> treeData(@PathVariable("caseNo") String caseNo) {
        List<ZtreeStr> ztrees = newCaseSeqService.selectTree(caseNo);
        return ztrees;
    }

    /**
     * 查询详情数据
     * @param caseQuery
     * @return
     */
    @RequestMapping("/listDetail")
    @ResponseBody
    public TableDataInfo listDetail(CaseQuery caseQuery) {
        startPage();
        List<Map> list = newCaseSeqService.selectCaseDetail(caseQuery);
        return getDataTable(list);
    }

}
